package com.njtcedu.microblog.common.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "content_topic", schema = "microblog")
public class ContentTopic implements Serializable {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private Integer id;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "content_id", nullable = false)
	private Content content;

	@ManyToOne(cascade = CascadeType.REFRESH, optional = false)
	@JoinColumn(name = "topic_id", nullable = false)
	private Topic topic;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Content getContent() {
		return content;
	}

	public void setContent(Content content) {
		this.content = content;
	}

	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	@Override
	public int hashCode() {

		return id != null ? id.hashCode() : 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || getClass() != obj.getClass())
			return false;
		ContentTopic contentTopic = (ContentTopic) obj;
		return id != null ? id.equals(contentTopic.id) : contentTopic.id == null;
	}

	@Override
	public String toString() {
		return "ContentTopic [id=" + id + ", content=" + content + ", topic="
				+ topic + "]";
	}

}
